﻿/*********************************************************************************
 * Copyright(c)  	2011 @kaleyroy
 * 创建日期：		2011-12-24 0:59:45 
 * 文 件 名：		ILinqRepository.cs 
 * CLR 版本: 		4.0.30319.239 
 * 创 建 者：		@kaleyroy 
**********************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using USS.Core;
using USS.Domain;
using USS.Repository.Context;
using LinqSpecs;

/// <summary>
/// 
/// 修改记录:
///	
/// </summary>
namespace USS.Repository
{
    /// <summary>
    /// 基于LinQ数据访问接口
    /// </summary>
    /// <typeparam name="TEntity">实体</typeparam>
    public abstract class USSRepository<TEntity> : IRepository<TEntity> where TEntity : class
    {

        /// <summary>
        /// USS数据上下文实例对象
        /// </summary>
        protected USSDataContext ussCxt = new USSContextFactory().Context();

        /// <summary>
        /// 添加实体
        /// </summary>
        /// <param name="entity">实体</param>
        public abstract void Add(TEntity entity);

        /// <summary>
        /// 是否存在实体
        /// </summary>
        /// <param name="specification">规格条件</param>
        /// <returns>是否符合条件实体</returns>
        public abstract bool Exists(Specification<TEntity> specification);

        /// <summary>
        /// 查找单个实体
        /// </summary>
        /// <param name="specification">规格条件</param>
        /// <returns>符合条件实体</returns>
        public abstract TEntity Find(Specification<TEntity> specification);

        /// <summary>
        /// 查找所有实体
        /// </summary>
        /// <returns>所有实体列表</returns>
        public abstract IEnumerable<TEntity> FindAll();

        /// <summary>
        /// 查找所有实体
        /// </summary>
        /// <param name="specification">规格条件</param>
        /// <returns>符合条件实体列表</returns>
        public abstract IEnumerable<TEntity> FindAll(Specification<TEntity> specification);

        /// <summary>
        /// 获取单个实体
        /// </summary>
        /// <param name="key">主键标识</param>
        /// <returns>匹配实体</returns>
        public abstract TEntity GetByKey(object key);

        /// <summary>
        /// 删除实体
        /// </summary>
        /// <param name="entity">实体</param>
        public abstract void Remove(TEntity entity);

        /// <summary>
        /// 更新实体
        /// </summary>
        /// <param name="entity">实体</param>
        public abstract void Update(TEntity entity);
    }
}
